

public class ComplexNumber {
	
	private double re;
	private double im;
	
	public ComplexNumber(double tempReal, double tempImag){
		re = tempReal;
		im = tempImag;
	}
	
	public ComplexNumber add(ComplexNumber b){
		ComplexNumber a = this;
		
		double tempReal = a.re + b.re;
		double tempImag = a.im + b.im;
		
		return new ComplexNumber(tempReal,tempImag);
	}
	
	public ComplexNumber subtract(ComplexNumber b){
		ComplexNumber a = this;
		
		double tempReal = a.re - b.re;
		double tempImag = a.im - b.im;
		
		return new ComplexNumber(tempReal,tempImag);
	}
	
	public ComplexNumber multi(ComplexNumber b){
		ComplexNumber a = this;
		
		double foil1 = a.re * b.re;
		double foil2 = a.re * b.im;
		double foil3 = a.im * b.re;
		double foil4 = (-1) * (a.im * b.im);
		
		double tempReal = foil1 + foil4;
		double tempImag = foil2 + foil3;
		
		return new ComplexNumber(tempReal,tempImag);
	}
	
	public ComplexNumber conjugate(){
		double tempReal = this.re;
		double tempImag = (-1) * this.im;
		
		return new ComplexNumber(tempReal, tempImag);
	}
	
	public ComplexNumber divide(ComplexNumber b){
		ComplexNumber a = this;
		ComplexNumber negB = b.conjugate();
		
		ComplexNumber top = a.multi(negB);
		
		ComplexNumber bottom = b.multi(negB);
		
		double bottom2 = bottom.re + bottom.im;
		
		return new ComplexNumber((top.re/bottom2),(top.im/bottom2));
	}
	
	public double getR(){
		return this.re;
	}
	
	public double getI(){
		return this.im;
	}
	 public String toString() {
	        if (im == 0) return re + "";
	        if (re == 0) return im + "i";
	        if (im <  0) return re + " - " + (-im) + "i";
	        return re + " + " + im + "i";
	 }
 	public void printString(){
		if(this.im > 0)
		System.out.println(this.re + " + " + this.im + "i");
		
		if(this.im == 0)
			System.out.println(this.re + " + 0i");
		
		if(this.im < 0){
			double tempImag = this.im * (-1);
			System.out.println(this.re + " - " + tempImag + "i");
		}
	}
}
